package WCC;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class WCDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        //定义输入输出路径
        args=new String[]{"E:\\test\\words\\word1(1.84M).txt","E:\\test\\temp\\output_combine"};

        //创建配置文件
        Configuration conf = new Configuration();
        //创建Job任务
        Job job = Job.getInstance(conf);

         //设置Driver反射
        job.setJarByClass(WCDriver.class);

        //设置Mapper反射
        job.setMapperClass(WCMapper.class);
        //设置Mapper的输出（key,value）类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

       /* //设置Reducer反射
        job.setReducerClass(WCReducer.class);
        //设置Reducer的输出（key,value）类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);*/
        //combine可以做与reduce一样的处理可以不甚至reduce反射
        //设置combine反射：在map之后，不影响业务逻辑前提下，先进行combine处理，减少 I/O。
        job.setCombinerClass(WCCombine.class);


        //指定输入输出路径
        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));
        //优先满足最小切片大小，不超过最大切片大小
       /* CombineFileInputFormat.setMaxInputSplitSize(job,4194304);//4M
        CombineFileInputFormat.setMinInputSplitSize(job,2097152);//2M*/
        //提交job任务到yarn执行
        boolean isSuccess = job.waitForCompletion(true);
        System.exit(isSuccess?0:-1);



    }
}
